package gcontent.init;

import java.net.URL;

import gcontent.config.Configure;
import gcontent.config.PersistentConfig;
import gcontent.entities.content.error.ContentEx;
import gcontent.entities.site.SiteURL;
import gcontent.launch.HasherThread;
import gcontent.launch.SpiderThread;
import gcontent.record.db.RecordDB;
import gcontent.record.error.RecordEx;


public class Init {
	
	public static void init_config() throws Exception
	{
		Configure.init();		
		PersistentConfig.init();
	}

	private static void cleanData(RecordDB record) throws RecordEx, ContentEx
	{
		record.execProc("PROC_CleanAllData");
	}
	
	public static void main(String args[])
	{
		try {			
			Configure.set("CONFIG_HTTP_PROXY_HOST", "10.49.1.1");
			Configure.set("CONFIG_HTTP_PROXY_PORT", "8080");
			RecordDB record;
			
			/* load configuration */
			init_config();	
		
			record = (RecordDB)Configure.getGlobalRecord();
			record.connect();

			/* mode debug, clean all data */
			if(System.getProperty("gcontent_debug") != null) 
				cleanData(record);
		
			HasherThread hasher = new HasherThread();
			hasher.start();
			
			SpiderThread spider = new SpiderThread(new SiteURL(new URL("http://maps.google.es")));
			spider.setDomainToks(2);
			spider.setMode(SpiderThread.MODE.FIRST_ONE_DOMAIN);
			spider.start();	
			
			SpiderThread spider2 = new SpiderThread(new SiteURL(new URL("http://www.t-systems.es")));
			spider2.setDomainToks(2);
			spider2.setMode(SpiderThread.MODE.FIRST_ONE_DOMAIN);
			spider2.start();					
			
			spider.join();
			spider2.join();
			
		} catch(Exception ex) {
			ex.printStackTrace();
		}		
	}
}
